package com.fun.feifun.modules.business.model.xml;

import com.fun.feifun.base.utils.MD5Util;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.xml.bind.annotation.XmlRootElement;

/**
 * @author wukefei
 * @date $ $
 */
@Data
@XmlRootElement(name = "OrderParam")
public class OrderParam {

    @ApiModelProperty(value = "商户编号")
    private String userid;

    @ApiModelProperty(value = "平台商品编号(向平台索取)。")
    private String productid;

    @ApiModelProperty(value = "充值金额（面值）整数")
    private String price;

    @ApiModelProperty(value = "订单商品数量（只能为1）")
    private String num;

    @ApiModelProperty(value = "充值账号:如:手机号")
    private String mobile;

    @ApiModelProperty(value = "代理商订单时间，(yyyyMMddHHmmss)")
    private String spordertime;

    @ApiModelProperty(value = "代理商系统订单号（流水号）要求不可重复")
    private String sporderid;

    @ApiModelProperty(value = "可以为空，加油卡持卡人手机号（不参与签名 ）")
    private String gascardtel;

    @ApiModelProperty(value = "可为空，加油卡持卡人姓名（不参与签名 ）")
    private String gascardname;

    //（注一）验证摘要串顺序规则:
    //sign=MD5(userid=xxxx&productid=xxxxxxx&price=xxxx&num=xxx&mobile=xxxxx&spordertime=xxxxxxx&sporderid=xxxxx&key=xxxxxxx).toUpperCase()
    //参数为空的时候传空字符串,不是传null.
    //xxxx为参数的值
    //userid和key 都由平台提供,请联系商务获取
    @ApiModelProperty(value = "签名验证摘要串")
    private String sign;

    @ApiModelProperty(value = "回调URL，（不参与签名 ）")
    private String back_url;

    @ApiModelProperty(value = "运营商类型，联通:lt 移动:yd 电信:dx")
    private String paytype;


    public String MD5Sign(String key) {
        String encrypt ="";
        try {
            StringBuilder signStr = new StringBuilder();
            signStr.append("userid="+this.getUserid()+"&");
            signStr.append("productid="+this.getProductid()+"&");
            signStr.append("price="+this.getPrice()+"&");
            signStr.append("num="+this.getNum()+"&");
            signStr.append("mobile="+this.getMobile()+"&");
            signStr.append("spordertime="+this.getSpordertime()+"&");
            signStr.append("sporderid="+this.getSporderid()+"&");
            signStr.append("key="+key);
            encrypt = MD5Util.encrypt(signStr.toString());
        }catch (Exception e){
            e.printStackTrace();
        }
        return encrypt;
    }

    @Override
    public String toString() {
        return "OrderParam{" +
                "userid='" + userid + '\'' +
                ", productid='" + productid + '\'' +
                ", price='" + price + '\'' +
                ", num='" + num + '\'' +
                ", mobile='" + mobile + '\'' +
                ", spordertime='" + spordertime + '\'' +
                ", sporderid='" + sporderid + '\'' +
                ", gascardtel='" + gascardtel + '\'' +
                ", gascardname='" + gascardname + '\'' +
                ", sign='" + sign + '\'' +
                ", back_url='" + back_url + '\'' +
                ", paytype='" + paytype + '\'' +
                '}';
    }
}
